package ir.sourcecodes.animalsounds;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.text.InputFilter;
import android.text.Spanned;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.MenuItemCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import java.util.ArrayList;
import java.util.Objects;

public class ActivityMain extends AppCompatActivity {
    /* access modifiers changed from: private */
    public static ActivityMain activity = null;
    public static String ad_app_image_address = "";
    public static String ad_app_link = "";
    public static String ad_app_text = "";
    public static String ad_banner_standard_activity_main_sound = "rayka";
    public static String ad_banner_standard_activity_tools_sound = "tapligh";
    public static String ad_full_pic_almabala_rayka = "rayka";
    public static int ad_full_pic_random_on_main = 0;
    public static String bgColor = null;
    public static int currentImageAdVersion = 0;
    public static boolean enable_adApp_server = false;
    public static String imageAddress = null;
    public static String link = null;
    public static boolean shopVisibility = false;
    public static String text = null;
    public static String textColor = null;
    public static int time_adApp_sec = 604800;
    public LinearLayout lnrRayka;
    public LinearLayout lnrTapligh;
    public LinearLayout lnrTapsell;
    public LinearLayout lnrZooItems2;
    /* access modifiers changed from: private */
    public RecyclerViewAdapter mAdapter;
    /* access modifiers changed from: private */
    public ArrayList<AbstractModel> modelList = new ArrayList<>();
    /* access modifiers changed from: private */
    public SharedPreferences prefs;
    private RecyclerView recyclerView;
    private Toolbar toolbar;
    public TextView txtZoo;
    public TextView txtZoo2;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        getWindow().addFlags(128);
        setContentView((int) R.layout.activity_main);

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
        activity = this;
        findViews();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            initToolbar("");
        }
        setAdapter();
        animations();
       // getRemoteConfigCheshmak();
//        this.txtZoo.setTextSize(0, (float) (G.width / 22));
       // this.txtZoo2.setTextSize(0, (float) (G.width / 24));
//        this.txtZoo.setTypeface(G.iranSansBold);
        this.txtZoo2.setTypeface(G.iranSansBold);

        ads.init(this);
        ads.showBan(this,this);
        ads.pushe(this);
    }

    private void findViews() {
        this.toolbar = (Toolbar) findViewById(R.id.toolbar);
        this.recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        this.lnrZooItems2 = (LinearLayout) findViewById(R.id.lnrZooItems2);
      //  this.txtZoo = (TextView) findViewById(R.id.txtZoo);
        this.txtZoo2 = (TextView) findViewById(R.id.txtZoo2);
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void initToolbar(String str) {
        setSupportActionBar(this.toolbar);
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setTitle((CharSequence) str);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu_search, menu);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
     //   searchView.setSearchableInfo(((SearchManager) getSystemService(FirebaseAnalytics.Event.SEARCH)).getSearchableInfo(getComponentName()));
        EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
        editText.setTextColor(ViewCompat.MEASURED_STATE_MASK);
        editText.setHintTextColor(-7829368);
        editText.setBackgroundColor(0);
        editText.setHint("جستجو");
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(40), new InputFilter() {
            public CharSequence filter(CharSequence charSequence, int i, int i2, Spanned spanned, int i3, int i4) {
                while (i < i2) {
                    if (!Character.isLetterOrDigit(charSequence.charAt(i))) {
                        return "";
                    }
                    i++;
                }
                return null;
            }
        }});
        searchView.findViewById(R.id.search_plate).setBackgroundColor(0);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            public boolean onQueryTextSubmit(String str) {
                return false;
            }

            public boolean onQueryTextChange(String str) {
                ArrayList arrayList = new ArrayList();
                if (str.length() > 0) {
                    for (int i = 0; i < ActivityMain.this.modelList.size(); i++) {
                        if (((AbstractModel) ActivityMain.this.modelList.get(i)).getTitle().toLowerCase().contains(str.toString().toLowerCase())) {
                            arrayList.add(ActivityMain.this.modelList.get(i));
                            ActivityMain.this.mAdapter.updateList(arrayList);
                        }
                    }
                } else {
                    ActivityMain.this.mAdapter.updateList(ActivityMain.this.modelList);
                }
                return false;
            }
        });
        return true;
    }

    private void setAdapter() {
        int i = 0;
        while (i < 114) {
         //   Resources resources = G.resources;
            StringBuilder sb = new StringBuilder();
            sb.append("t_persian");
            i++;
            sb.append(i);
            String string = getString(G.resources.getIdentifier(sb.toString(), "string", G.packageName));
            Resources resources2 = G.resources;
            String string2 = getString(resources2.getIdentifier("t_english" + i, "string", G.packageName));
            this.modelList.add(new AbstractModel(string, string2, "p" + i));
        }
        this.mAdapter = new RecyclerViewAdapter(this, this.modelList);
        this.recyclerView.setHasFixedSize(true);
        this.recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        this.recyclerView.setAdapter(this.mAdapter);
        this.mAdapter.SetOnItemClickListener(new RecyclerViewAdapter.OnItemClickListener() {
            public void onItemClick(View view, int i, AbstractModel abstractModel) {
            }
        });
    }

    public void animations() {
       //this.txtZoo.startAnimation(G.scaleBigFadeAnim);
        this.txtZoo2.startAnimation(G.scaleBigFadeAnim);
        G.scaleBigFadeAnim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationStart(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
//                ActivityMain.this.txtZoo.setText("Apps / برنامه ها");
                ActivityMain.this.txtZoo2.setText("Apps / برنامه ها");
//                ActivityMain.this.txtZoo.startAnimation(G.enterJumpAnim);
                ActivityMain.this.txtZoo2.startAnimation(G.dropBounceAnim);
//                ActivityMain.this.txtZoo.setBackgroundResource(R.drawable.shape_item_up_zoo3);
              //  ActivityMain.this.txtZoo2.setBackgroundResource(R.drawable.shape_item_up_zoo4);
            }
        });
    }



    /* access modifiers changed from: protected */
    public void onStop() {
        super.onStop();
        G.app.tryToStopPlayer();
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        G.app.tryToStopPlayer();
    }

  /*  public void onBackPressed() {
       G.app.tryToStopPlayer();
        if (enable_adApp_server) {
           // readAd();
            return;
        }
    }*/


/*    public void readAd() {
        ModuleWebservice moduleWebservice = new ModuleWebservice();
        moduleWebservice.url("http://www.faradteam.ir/jafarMazareei/adService.php?action=_readAd").inputArguments("params_ID").listener(new ModuleWebservice.Listener() {
            public void onDataReceive(String str) {
                try {
                    JSONObject jSONObject = new JSONArray(str).getJSONObject(0);
                    ActivityMain.text = jSONObject.getString("text");
                    ActivityMain.imageAddress = jSONObject.getString("imageAddress");
                    ActivityMain.link = jSONObject.getString("link");
                    ActivityMain.currentImageAdVersion = jSONObject.getInt("imageAdVersion");
                    ActivityMain.bgColor = jSONObject.getString("bgColor");
                    ActivityMain.textColor = jSONObject.getString("textColor");
                    ActivityMain.activity.runOnUiThread(new Runnable() {
                        public void run() {
                            ActivityMain.this.dialogClose(ActivityMain.text, ActivityMain.imageAddress, ActivityMain.link, ActivityMain.bgColor, ActivityMain.textColor);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.i("JAFAR", "fail1");
                    Log.i("destroy1 ", e.getMessage());
                }
            }

            public void onFail(int i) {
                Log.i("JAFAR", "fail2");
                ActivityMain.activity.runOnUiThread(new Runnable() {
                    public void run() {
                        ActivityMain.this.dialogClose("", "", "", "", "");
                    }
                });
            }
        }).enableCachePrefs(true).cachePrefsExpireTime((long) time_adApp_sec).connectionTimeout(2).socketTimeout(2).read();
    }*/

    public int loadVersionOfPrefs(int i) {
        SharedPreferences sharedPreferences = G.context.getSharedPreferences("AD", 0);
        this.prefs = sharedPreferences;
        return sharedPreferences.getInt("IMAGEADVERSION" + i, 0);
    }

    public void saveVersionToPrefs(final int i, final int i2) {
        new Handler().postDelayed(new Runnable() {
            public void run() {
                SharedPreferences unused = ActivityMain.this.prefs = G.context.getSharedPreferences("AD", 0);
                SharedPreferences.Editor edit = ActivityMain.this.prefs.edit();
                edit.putInt("IMAGEADVERSION" + i2, i);
                edit.commit();
            }
        }, 100);
    }


    public void otherApps(View view) {

                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityMain.this);
                builder.setMessage("توسعه نرم افزار دانشمند\n" +
                        "پشتیبانی : rezamostafazadeh20@gmail.com\n" +
                        "از این که ما را انتخاب کردید سپاسگذاریم \n");
                builder.setPositiveButton("سایر برنامه ها", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                            intent.setData(Uri.parse("https://play.google.com/store/apps/developer?id=Scientist"));
                            startActivity(intent);

                        }catch (Exception e){

                        }

                    }

                });
                builder.setNegativeButton("بستن", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                builder.show();

    }
}
